#!/usr/bin/env python
#
#       browser.py
#       
#       Copyright 2009 Matthew Brush <mbrush AT leftclick DOT ca>
#       
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.
#
import gtk
import gtksourceview2 as gtksourceview
import pango
import browser

class CodeView(gtksourceview.View):
    # seriously, WTF?  there has to be a way to say: USE PHP
    def get_language_for_mime_type(self, mime):
        lang_manager = gtksourceview.language_manager_get_default()
        lang_ids = lang_manager.get_language_ids()
        for i in lang_ids:
            lang = lang_manager.get_language(i)
            for m in lang.get_mime_types():
                if m == mime:
                    return lang
        return None
    
    def __init__(self):
        gtksourceview.View.__init__(self)
        
        # Set defaults, later to be read from config file
        self.set_show_line_numbers(True)
        self.set_tab_width(4)
        self.set_auto_indent(True)
        #self.sourceview.set_margin(80)
        #self.sourceview.set_show_margin(True)
        self._font_desc = pango.FontDescription('monospace normal 10')
        self.modify_font(self._font_desc)
        # Create source view buffer component
        self.sourceviewbuffer = gtksourceview.Buffer()
        self.lang_manager = gtksourceview.language_manager_get_default()
        self.lang = self.get_language_for_mime_type("text/x-php")
        self.sourceviewbuffer.set_language(self.lang)
        self.sourceviewbuffer.set_text("""<?php

error_reporting(E_ALL);
ini_set("display_errors", 1);

?>

<html>
    <head>
        <title>Untitled</title>
    </head>
    <body>
        <h1>Untitled</h1>
    </body>
</html>
""")

class Preview(browser.WebBrowserBox):
    def __init__(self):
        browser.WebBrowserBox.__init__(self, toolbar=False, statusbar=False)
        

class Editor(gtk.Notebook):
    def __init__(self):
        gtk.Notebook.__init__(self)
        
        self.set_tab_pos(gtk.POS_BOTTOM)
        
        self._codeview = CodeView()
        self._preview = Preview()

        self._codeview_label = gtk.Label("Code View")
        self._preview_label = gtk.Label("Preview")
             
        self.append_page(self._codeview, self._codeview_label)
        self.append_page(self._preview, self._preview_label)
        
        self._codeview.show()
        self._preview.show()
        
        self.set_current_page(0)
        
        self.ever_saved = False
        
        
        
        
        
        
        
        
        
        
        
